package com.platform.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.Maps;
import com.platform.comm.constants.EnumOption;
import com.platform.comm.enums.BaseEnum;
import com.platform.comm.enums.IEnumOption;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Description: 菜单类型枚举
 *
 * @author wxw Created on 2021/07/28
 **/
@EnumOption(name = "functionType")
public enum FunctionType implements BaseEnum<String>, IEnumOption<String> {

    /**
     * 功能菜单
     */
    FUN("1", "功能菜单"),
    /**
     * 目录菜单
     */
    DIR("2", "目录菜单"),
    /**
     * 动作菜单
     */
    ACT("3", "动作菜单");

    private final String value;
    private final String text;

    FunctionType(String value, String text) {
        this.value = value;
        this.text = text;
    }

    @JsonValue
    @Override
    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public static FunctionType getByValue(String value) {
        if (value.equals(FUN.value)) {
            return FUN;
        } else if (value.equals(DIR.value)) {
            return DIR;
        } else if (value.equals(ACT.value)) {
            return ACT;
        } else {
            return null;
        }
    }

    public static Map<String, String> getAllValues() {
        Map<String, String> map = Maps.newHashMap();
        Stream.of(values()).forEach(mode -> map.put(mode.value, mode.text));
        return map;
    }


    @Override
    public String key() {
        return value;
    }

    @Override
    public String value() {
        return text;
    }

    @Override
    public Map<String,String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }
}
